package com.gr100.biz.api.order;

import com.gr100.biz.api.bo.MetaObject;
import com.gr100.biz.api.order.hex.ValidateHex;
import com.mysql.jdbc.StringUtils;

/**
 * Created by james on 16/3/15.
 */
public class Order {

    public enum ORDER_TYPE{
        //0:普通订单 8:营销订单 9:甩单订单 11:退货订单 12:换货订单 13：第三方订单（百度，美团，饿了么） 14：自提订单
        PT("0"),YX("8"),SD("9"),TH("11"),HH("12"),DSF("13"),ZT("14");

        private String _ordertype;
        ORDER_TYPE(String ordertype){
            _ordertype = ordertype;
        }

        public boolean equal(String ordertype){
            return this._ordertype.equalsIgnoreCase(ordertype);
        }

    }

    private String _par,_gCoin,_expresscost,_discount,_total,_finalAmount,_orderid,_groupNo,_type,_toName,_toPhone,_toStreet,_remark,_areaName,_shopName,_uid,_couponId,_sjc,_confidence,_toProvince,_toCity,_bookdate,_expressname,_expresstype,_deliveryTime,_TimingPrice,_level,_mj_title,_mj_amount,_couponDiscountId,_couponDiscountPar;
    private double _lng,_lat;
    private int _gCoinChecked,_areaId,_shopId,_UserTimingCouponId,_MemberTimingCouponId;


    public Order(String orderid,String groupNo,String type,String toProvince,String toCity,String toName,String toPhone,String toStreet,String total,String finalAmount,String discount,String remark,int areaId,String areaName,int shopId,String shopName,String uid,String couponId,String par,String sjc,int gCoinChecked,String gCoin,double lng,double lat,String level,String confidence,String bookdate,String expresscost,String expressname,String expresstype,String deliveryTime,int UserTimingCouponId,int MemberTimingCouponId,String TimingPrice,String mj_title,String mj_amount,String couponDiscountId,String couponDiscountPar) {
        this._orderid = orderid;
        this._groupNo = groupNo;
        this._type = type;
        this._toName = toName;
        this._toPhone = toPhone;
        this._toStreet = toStreet;
        this._total = total;
        this._finalAmount = finalAmount;
        this._discount = discount;
        this._remark = remark;
        this._areaName = areaName;
        this._shopName = shopName;
        this._uid = uid;
        this._couponId = couponId;
        this._par = par;
        this._sjc = sjc;
        this._gCoinChecked = gCoinChecked;
        this._gCoin = gCoin;
        this._areaId = areaId;
        this._shopId = shopId;
        this._lng = lng;
        this._lat = lat;
        this._level = level;
        this._confidence = confidence;
        this._toProvince = toProvince;
        this._toCity = toCity;
        this._bookdate = bookdate;
        this._expresscost = expresscost;
        this._expressname = expressname;
        this._expresstype = expresstype;
        this._deliveryTime = deliveryTime;
        this._TimingPrice = TimingPrice;
        this._UserTimingCouponId = UserTimingCouponId;
        this._MemberTimingCouponId = MemberTimingCouponId;
        this._mj_title = mj_title;
        this._mj_amount = mj_amount;
        this._couponDiscountId = couponDiscountId;
        this._couponDiscountPar = couponDiscountPar;
    }

    public String getOrderId() {
        return _orderid;
    }

    public String getGroupNo() {
        return _groupNo;
    }

    public String getType() {
        return _type;
    }

    public String getToName() {
        return _toName;
    }

    public String getToPhone() {
        return _toPhone;
    }

    public String getToStreet() {
        return _toStreet;
    }

    public String getTotal() {
        return _total;
    }

    public String getFinalAmount() {
        return _finalAmount;
    }

    public String getDiscount() {
        return _discount;
    }

    public int getAreaId() {
        return _areaId;
    }

    public int getShopId() {
        return _shopId;
    }

    public String getRemark() {
        return _remark;
    }

    public String getAreaName() {
        return _areaName;
    }

    public String getShopName() {
        return _shopName;
    }

    public String getUid() {
        return _uid;
    }

    public String getCouponId() {
        return _couponId;
    }

    public String getPar() {
        return _par;
    }

    public String getSJC() {
        return _sjc;
    }

    public int getgCoinChecked() {
        return _gCoinChecked;
    }

    public double getLng() {
        return _lng;
    }

    public double getLat() {
        return _lat;
    }

    public String getConfidence() {
        return _confidence;
    }

    public String getToProvince() {
        return _toProvince;
    }

    public String getBookdate() {
        return _bookdate;
    }

    public String getDeliveryTime() {
        return _deliveryTime;
    }

    public String getToCity() {
        return _toCity;
    }

    public String getgCoin() {
        return _gCoin;
    }

    public String getExpresscost() {
        return _expresscost;
    }

    public String getExpressname() {
        return _expressname;
    }

    public String getExpresstype() {
        return _expresstype;
    }

    public String getTimingPrice() {
        return _TimingPrice;
    }

    public int getUserTimingCouponId() {
        return _UserTimingCouponId;
    }

    public int getMemberTimingCouponId() {
        return _MemberTimingCouponId;
    }

    public String getlevel() {
        return _level;
    }

    public String getmjtitle() {
        return _mj_title;
    }

    public String getmjamount() {
        return _mj_amount;
    }

    public String getcouponDiscountId() {
        return _couponDiscountId;
    }

    public String getcouponDiscountPar() {
        return _couponDiscountPar;
    }

    /**
     * 非空验证
     * @return
     */
    public void validate() throws ValidateHex {

        if(StringUtils.isNullOrEmpty(_type)){
            throw new ValidateHex(-701,"TYPE CANT BE EMPTY","订单类型不能为空");
        }
        if(!ORDER_TYPE.PT.equal(_type) && !ORDER_TYPE.YX.equal(_type) && !ORDER_TYPE.SD.equal(_type) && !ORDER_TYPE.TH.equal(_type) && !ORDER_TYPE.HH.equal(_type) && !ORDER_TYPE.DSF.equal(_type) && !ORDER_TYPE.ZT.equal(_type)){
            throw new ValidateHex(-702,"TYPE ABNORMAL VALUE","订单类型值异常");
        }
        if(StringUtils.isNullOrEmpty(_toName)){
            throw new ValidateHex(-703,"TONAME CANT BE EMPTY","收货人姓名不能为空");
        }
        if(StringUtils.isNullOrEmpty(_toPhone)){
            throw new ValidateHex(-704,"TOPHONE CANT BE EMPTY","收货人联系电话不能为空");
        }
        if(StringUtils.isNullOrEmpty(_toStreet)){
            throw new ValidateHex(-705,"TOSTREET CANT BE EMPTY","收货地址不能为空");
        }
//        if(StringUtils.isNullOrEmpty(_total)){
//            throw new ValidateHex(-706,"TOTAL CANT BE EMPTY","订单金额不能为空");
//        }
        if(StringUtils.isNullOrEmpty(_uid)){
            throw new ValidateHex(-707,"UID CANT BE EMPTY","用户编号不能为空");
        }
        if(ORDER_TYPE.YX.equal(_type) && StringUtils.isNullOrEmpty(_areaName)){
            throw new ValidateHex(-710,"AREANAME CANT BE EMPTY","区域不能为空");
        }
        if(ORDER_TYPE.YX.equal(_type) &&StringUtils.isNullOrEmpty(_shopName)){
            throw new ValidateHex(-711,"SHOPNAME CANT BE EMPTY","果饮店不能为空");
        }
        if(ORDER_TYPE.YX.equal(_type) && StringUtils.isNullOrEmpty(_areaName) && !"A1".equals(_areaName) && !"A2".equals(_areaName) && !"A3".equals(_areaName) && !"B1".equals(_areaName) && !"B2".equals(_areaName) && !"W1".equals(_areaName) && !"W2".equals(_areaName) && !"W3".equals(_areaName)){
            throw new ValidateHex(-712,"AREANAME ABNORMAL VALUE","区域值异常");
        }
        if(ORDER_TYPE.YX.equal(_type) &&StringUtils.isNullOrEmpty(_shopName) && !"果然总部".equals(_shopName) && !"京华城店".equals(_shopName) && !"虹桥坊店".equals(_shopName) && !"梅岭店".equals(_shopName) && !"望月店".equals(_shopName) && !"时代店".equals(_shopName) && !"三盛店".equals(_shopName)){
            throw new ValidateHex(-713,"SHOPNAME ABNORMAL VALUE","果饮店值异常");
        }
    }

    /**
     * 验证用户购车内是否有商品
     * @return
     */
    public boolean checkExists(){
        return OrderModel.me().checkExists(this);
    }

    /**
     * 验证用户购车内是否有商品
     * @return
     */
    public boolean checkInvalid(){
        return OrderModel.me().checkInvalid(this);
    }

    /**
     * 验证商品库存是否充足
     * @return
     */
    public boolean checkInventory(){
        return OrderModel.me().checkInventory(this);
    }

    /**
     * 验证订单原价是否正确
     * @return
     */
    public boolean checkAmount(){
        return OrderModel.me().checkAmount(this);
    }

    /**
     * 验证订单实付金额是否正确
     * @return
     */
    public boolean checkFinalAmount(){
        return OrderModel.me().checkFinalAmount(this);
    }

    /**
     * 验证用户定时券
     * @return
     */
    public boolean checkUserTimingCouponId(){
        return OrderModel.me().checkUserTimingCouponId(this);
    }

    /**
     * 验证会员定时券
     * @return
     */
    public boolean checkMemberTimingCouponId(){
        return OrderModel.me().checkMemberTimingCouponId(this);
    }

    /**
     * 验证会员折扣是否正确
     * @return
     */
    public boolean checkDiscount(){
        return OrderModel.me().checkDiscount(this);
    }

    /**
     * 验证优惠券是否正确
     * @return
     */
    public boolean checkCoupon(){
        return OrderModel.me().checkCoupon(this);
    }

    /**
     * 验证折扣优惠券是否正确
     * @return
     */
    public boolean checkCouponDiscount(){
        return OrderModel.me().checkCouponDiscount(this);
    }

    /**
     * 验证活动余额是否正确
     * @return
     */
    public boolean checkgCoin(){
        return OrderModel.me().checkgCoin(this);
    }

    /**
     * 删除用户购物车商品
     * @return
     */
    public boolean delCart(){
        return OrderModel.me().delCart(this);
    }

    /**
     * 新建订单
     * @return
     */
    public int save(){
        return OrderModel.me().save(this);
    }

    /**
     * 扣减用户余额
     * @return
     */
    public int lessenBalance(String uid,double finalAmount,String content){
        return OrderModel.me().lessenBalance(uid, finalAmount, content);
    }

    /**
     * 扣减用户活动余额
     * @return
     */
    public int lessengCoin(String uid,double gCoin,String content){
        return OrderModel.me().lessengCoin(uid, gCoin, content);
    }

    /**
     * 更新优惠券使用状态
     * @return
     */
    public int updateCouponId(){
        return OrderModel.me().updateCouponId(this);
    }

    /**
     * 更新折扣优惠券使用状态
     * @return
     */
    public int updateDiscountCouponId(){
        return OrderModel.me().updateDiscountCouponId(this);
    }

    /**
     * 更新用户定时券使用状态
     * @return
     */
    public int updateUserCouponId(){
        return OrderModel.me().updateUserCouponId(this);
    }

    /**
     * 更新会员定时券使用状态
     * @return
     */
    public int updateMemberCouponId(){
        return OrderModel.me().updateMemberCouponId(this);
    }

    /**
     * 更新商品库存
     * @return
     */
    public int minusInventory(){
        return OrderModel.me().minusInventory(this);
    }
}
